package test.reflection;

import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MethodTest1 {
    public static void a() {

    }

    public String b() {
        return "b";
    }

    public <T> List<T> c() {
        return new ArrayList<T>();
    }

    public static void main(String[] args) throws NoSuchMethodException {
        MethodTest1 methodTest1 = new MethodTest1();
        //[public static void test.reflection.MethodTest1.main(java.lang.String[]), public java.util.List test.reflection.MethodTest1.c(), public static void test.reflection.MethodTest1.a(), public java.lang.String test.reflection.MethodTest1.b()]
        System.out.println(Arrays.toString(methodTest1.getClass().getDeclaredMethods()));
        //[public static void test.reflection.MethodTest1.main(java.lang.String[]), public java.util.List test.reflection.MethodTest1.c(), public static void test.reflection.MethodTest1.a(), public java.lang.String test.reflection.MethodTest1.b(), public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException, public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException, public final void java.lang.Object.wait() throws java.lang.InterruptedException, public boolean java.lang.Object.equals(java.lang.Object), public java.lang.String java.lang.Object.toString(), public native int java.lang.Object.hashCode(), public final native java.lang.Class java.lang.Object.getClass(), public final native void java.lang.Object.notify(), public final native void java.lang.Object.notifyAll()]
        System.out.println(Arrays.toString(methodTest1.getClass().getMethods()));


        System.out.println();
        System.out.println(MethodTest1.class.getMethod("c").getGenericReturnType()); // java.util.List<T>
        System.out.println(MethodTest1.class.getMethod("c").getGenericReturnType().getTypeName()); // java.util.List<T>
        System.out.println(MethodTest1.class.getMethod("c").getGenericReturnType().getClass()); // class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
        System.out.println(((ParameterizedTypeImpl)MethodTest1.class.getMethod("c").getGenericReturnType()).getRawType()); // interface java.util.List
        System.out.println(((ParameterizedTypeImpl)MethodTest1.class.getMethod("c").getGenericReturnType()).getOwnerType()); // null
        System.out.println(MethodTest1.class.getMethod("c").getReturnType()); // interface java.util.List

    }
}
